import logging
import time

from channels.layers import get_channel_layer

from account.trade import handle_cancel_order, get_order_trading_amount
from libs.common import success

logger = logging.getLogger(__name__)


def timestamp(request):
    return success(timestamp=int(time.time()))


def ping(request):
    return success('pong')


async def test(request):
    channel_layer = get_channel_layer()
    payload = {
        'type': 'goods.price',
        'data': {
            'symbol': 'symbol',
            'price': 100
        },
    }
    await channel_layer.group_send('market', payload)
    return success('pong')


def test_get_order(request):
    # handle_cancel_order('8287a2a2-c98f-4d6d-a553-1d9203970b99')
    get_order_trading_amount('93ba1fe0-2ff5-4438-8a78-46e27ebfe9b0')
    return success('pong')
